'use strict'

module.exports = app => {
	const { STRING, INTEGER, DATE } = app.Sequelize
	const User = app.model.define('user', {
		id: { type: INTEGER, primaryKey: true, autoIncrement: true },
		username: {
			type: STRING(30),
			field: '_username',
			comment: '用户名',
		},
		password: {
			type: STRING(30),
			field: '_password',
			comment: '密码',
		},
		invitationCode: {
			type: STRING(12),
			comment: '邀请码',
		},
		status: {
			type: INTEGER,
			field: '_status',
			comment: '禁用状态 0禁用 1启用',
		},
		createdAt: DATE,
		updatedAt: DATE,
	})

	User.associate = function () {
		app.model.User.hasMany(app.model.Article, { foreignKey: 'authorId' })
		app.model.User.belongsTo(app.model.UserInfo, {
			foreignKey: 'id',
			targetKey: 'userId',
		})
	}
	return User
}
